#include "Plane.h"


Plane::Plane(Vector3d pos,Vector3d norm) : RenderObject(pos),normal(norm)
{
}

Plane::Plane()
{
}


Plane::~Plane(void)
{
}

TraceResult Plane::collision(const Ray &ray)
{

	if ( normal.dot( ray.direction ) <= 0 )
	{
		double d = position.dot(normal);

		double a = ray.position.dot( normal);
		double b = ray.direction.dot(normal);

		double t = (d-a)/b;

		Vector3d point = static_cast<Vector3d>(ray.position) + (static_cast<Vector3d>(ray.direction) * t);

		return TraceResult(true,t,point,normal,this);
	}
	else
	{
		return TraceResult::empty;
	}
}
